mui.plusReady(function() {
		
	var $ = mui;
	var doc = document;
	
	var url = weburl + 'Home/ChatApi/getTradeList';
	
	var user = app.getState();
	var uid = user.user_id;

	var self = plus.webview.currentWebview();

	var coindata = ethscan.getCoindata(self.token);
	var coinname = coindata['name'];
	
	doc.getElementById('sale_type').innerHTML = '出售' + coinname;
	doc.getElementById('buy_type').innerHTML = '购买' + coinname;
	

	doc.getElementById('buy_type').addEventListener('tap', function() {
		doc.getElementById('area1').style.display = '';
		doc.getElementById('area2').style.display = 'none';
		doc.getElementById('sale_type').classList.remove('buy-active');
		doc.getElementById('buy_type').classList.add('buy-active');
	});
	
	doc.getElementById('sale_type').addEventListener('tap', function() {
		doc.getElementById('area1').style.display = 'none';
		doc.getElementById('area2').style.display = '';
		doc.getElementById('buy_type').classList.remove('buy-active');
		doc.getElementById('sale_type').classList.add('buy-active');
		
		if (!refreshSale.excuted) {
			refreshSale.excuted = 1;
			refreshSale();
		}
	});
	
	
	$(".mui-content").on('tap', "li", function() {
		var xcurrentCoin = this.getAttribute("value");
		$.openWindow({
			url: 'detail.html',
			id: 'marketdetail',
			extras: {
				token: xcurrentCoin,
				dataid: this.id
			},
			createNew: true
		});
	});
	
	
	
	function refreshBuy() {
		gatc.lazyload('#area1', {
			loadData: getBuyRecord
		});
	}
	
	function getBuyRecord(page, size, callback) {
		
		//var uid = 179020;
		var postdata = {
			uid: uid,
			page: page,
			size: size,
			type: 1,
			btype: self.token
		};
		console.log(JSON.stringify(postdata));
		$.post(url, postdata, function(res) {
			var list = res.data;
			
			if(list && list.length > 0) {
				callback(template("tpl", {
					data: list
				}), list.length);
			} else {
				callback('', 0);
			}
		});
	}
	
	
	function refreshSale() {
		gatc.lazyload('#area2', {
			loadData: getSaleRecord
		});
	}
	
	
	function getSaleRecord(page, size, callback) {
		
		//var uid = 179020;
		var postdata = {
			uid: uid,
			page: page,
			size: size,
			type: 2,
			btype: self.token
		};
		console.log(url);
		$.post(url, postdata, function(res) {
			var list = res.data;
			
			if(list && list.length > 0) {
				callback(template("tpl", {
					data: list
				}), list.length);
			} else {
				callback('', 0);
			}
		});
	}
	
	
	refreshBuy();
	
});
	